<?php

class Pesan_Dao{

	function __construct(){
		$koneksi = new Koneksi();
		$koneksi->_connect();
	}
	
	function add(Pesan $pesan){
		
		$sql = "
			INSERT 
			INTO
			carapesan
			(
				carapesan
			)
			VALUES
			(
				'".$pesan->carapesan."'
			)
		";
		mysql_query($sql);
	
	}
	
	function get($id_pesan){
	
		
		$sql = "
		SELECT
		*
		FROM
		carapesan
		WHERE
		id_pesan = '".$id_pesan."'
		";
		
		$pesan = false;
		
		$res = mysql_query($sql);
		
		if($res){
		
			$row = mysql_fetch_assoc($res);
		
			$pesan = new Pesan();
			$pesan->id_pesan = $row['id_pesan'];
			$pesan->carapesan = $row['carapesan'];
		}
		
		return $pesan;
	}
	function get_all(){
	
		$sql = "
		SELECT
		*
		FROM
		carapesan
		";
		
		$list_pesan = array();
		
		$res = mysql_query($sql);
		if($res){
			while($row = mysql_fetch_assoc($res)){
			
				$pesan = new Pesan();
				
				$pesan->id_pesan = $row['id_pesan'];
				$pesan->carapesan = $row['carapesan'];
				
				$list_pesan[] = $pesan;
			
			}
		}
				return $list_pesan;
	
	}
		function edit(Pesan $pesan){
		$sql ="
			UPDATE 
			carapesan
			SET
			carapesan='$pesan->carapesan'
			WHERE 
			id_pesan ='$pesan->id_pesan'
		";
		mysql_query($sql);
	
	}
	}
	class Pesan{

	var $id_pesan;
	var $carapesan;
	

}